home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Advanced I⁄O v2.3 / Advanced i⁄o / histogram.h < prev    next >
Text File  |  1995-05-07  |  1KB  |  58 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /*
  3.  ************************************************************************
  4.  *
  5.  *        Histogram of an integer-valued distribution
  6.  *
  7.  * $Id$
  8.  *
  9.  ************************************************************************
  10.  */
  11.  
  12. #ifndef __GNUC__
  13. #pragma once
  14. #endif
  15.  
  16. #ifndef _histogram_h
  17. #define _histogram_h
  18.  
  19. #ifdef __GNUC__
  20. #pragma interface
  21. #endif
  22.  
  23.                 // Computes the histogram of a sequence
  24.                 // of integers with unit bin size
  25. class Histogram
  26. {
  27.   unsigned int * counts;        // Counts for the symbols
  28.  
  29.   void operator = (Histogram&);        // Not implemented! Disallows assignments
  30.  
  31. public:
  32.   typedef short Symbol;
  33.  
  34.   const Symbol symbol_lwb;        // Region potential input symbols
  35.   const Symbol symbol_upb;        // are expected in
  36.   const int no_potential_symbols;    // Width of the region
  37.   
  38.                     // Construct a model for symbols
  39.                     // in [lwb,upb]
  40.   Histogram(const Symbol lwb, const Symbol upb);
  41.   ~Histogram(void);
  42.  
  43.   void put(const Symbol symbol);    // Count a symbol
  44.   void put_coerce(const Symbol symbol);    // Count a symbol coercing it to
  45.                       // the interval [lwb,upb]
  46.   int get(const Symbol symbol) const;    // Get a count for a specific symbol
  47.   int no_distinct_symbols() const;    // Give the no. of distinct symbols
  48.  
  49.   double estimate_entropy(void) const;    // Estimate zero-order entropy of a
  50.                     // source represented by the histogram
  51.  
  52.                     // Print the histogram
  53.   void print(const char * title="") const;
  54. };
  55.  
  56.  
  57. #endif
  58.